<?php
/**
 * The database class. A driver is plugged into this object.
 * Essentially it just creates a driver object and stores it.
 */
class Database {
    /**
     * The driver object. Not currently used.
     */
    static protected $driver = null;

    /**
     * A static factory function for creating driver instances.
     * @param Config_Section $config
     * @return Database_Driver
     * @throws Database_Exception
     */
    static public function factory(Config_Section $config) {
        $driver = $config->driver;
        if(!empty($driver)) {
            $classname = 'Database_Driver_' . ucfirst(strtolower($driver));
            $db = new $classname($config);
            if($db instanceof Database_Driver_Abstract && $db instanceof Database_Driver) {
                return $db;
            } else {
                throw new Database_Exception("'$classname' is not a database driver.");
            }
        } else {
            throw new Database_Exception('No driver name supplied.');
        }
    }
}
?>